package cn.ghx.xboot.order.demand;

import cn.ghx.xboot.common.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order/demand")
public class OrderDemandController {

    public static final String POST = "";
    public static final String GET_LIST = "/list";
    public static final String DELETE = "/{id}";
    public static final String GET_BY_ID = "/{id}";

    private final OrderDemandService service;

    public OrderDemandController(OrderDemandService service) {
        this.service = service;
    }

    @GetMapping(GET_BY_ID)
    public Result<OrderDemand> getById(@PathVariable String id){
        return Result.success(service.findById(id));
    }


    @DeleteMapping(DELETE)
    public Result<Boolean> delete(@PathVariable String id){
        return Result.success(service.deleteById(id));
    }

    @PostMapping(POST)
    public Result<Boolean> save(@RequestBody OrderDemand item){
        return Result.success(service.saveItem(item));
    }

    @GetMapping(GET_LIST)
    public Result<Page<OrderDemand>> getList(
            @RequestParam(required = false) String keyword ,
            @RequestParam(required = false) String province ,
            @RequestParam(required = false) String city ,
            @RequestParam(required = false) String district ,
            @RequestParam(required = false) String openid ,
            @RequestParam(required = false) String storeId ,
            @RequestParam(required = false,defaultValue = "1") Integer page ,
            @RequestParam(required = false,defaultValue = "10") Integer size){
        return Result.success(service.query(keyword,
                province ,
                city ,
                district ,
                openid ,
                storeId ,
                page,size));
    }
}
